<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.net.*"%>
<%@page import="java.sql.*"%>
<%@page import="org.json.simple.*"%>
<%@page import="java.util.*"%>
<%@page import="connection.DbConnection"%>
<%	
	//Establish database connection, get table data.
		DbConnection conn = new DbConnection();
		System.out.println("here! getTimer");
		int QuestionID = Integer.parseInt(request.getParameter("questionid"));
		String sql = "SELECT status, currentTimer FROM Question WHERE QuestionID="+QuestionID;
		PreparedStatement ps = conn.getConn().prepareStatement(sql);
		System.out.println("SQL:"+sql);
		int timer = -1;
		int status = -1;
		try{
			System.out.println("here! getTimer2");
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				System.out.println("here! getTimer3");
				System.out.flush();
				status = rs.getInt(1);
				timer = rs.getInt(2);
			}
		}catch(Exception e){
			System.out.println("Error in getTimer!");
		}
		try{
			if(timer != -1){
				session.setAttribute("timer", timer);
			}
			
			
			JSONObject obj = new JSONObject();
			obj.put("timer", timer);
			obj.put("status", status);
			out.print(obj);
			out.flush();
		}catch(Exception e){
			System.out.println("Problem's here!");
		}
		
%>